<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>设置日期</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="datetime.set-state.html">« DateTime::__set_state</a></li>
      <li style="float: right;"><a href="datetime.setisodate.html">DateTime::setISODate »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.datetime.html">DateTime</a></li>
    <li>设置日期</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="datetime.setdate" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DateTime::setDate</h1>
  <h1 class="refname">date_date_set</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.2.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">DateTime::setDate</span> -- <span class="refname">date_date_set</span> &mdash; <span class="dc-title">设置日期</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-datetime.setdate-description">
  <h3 class="title">说明</h3>
  <p class="para">面向对象风格</p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DateTime::setDate</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$year</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$month</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$day</code></span>): <span class="type"><a href="class.datetime.html" class="type DateTime">DateTime</a></span></div>

  <p class="para rdfs-comment">过程化风格</p>
  <div class="methodsynopsis dc-description"><span class="methodname"><a href="function.date-date-set.html" class="methodname">date_date_set</a></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="class.datetime.html" class="type DateTime">DateTime</a></span> <code class="parameter">$object</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$year</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$month</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$day</code></span><br>): <span class="type"><a href="class.datetime.html" class="type DateTime">DateTime</a></span></div>

  <p class="para rdfs-comment">
   将 DateTime 对象的当前日期重置为其它日期。
  </p>
  <p class="para">
   跟 <span class="methodname"><a href="datetimeimmutable.setdate.html" class="methodname">DateTimeImmutable::setDate()</a></span> 一样，但适用于
   <span class="classname"><a href="class.datetime.html" class="classname">DateTime</a></span>，且更改现有对象。
  </p>
  <p class="para">
   过程化版本将 <span class="classname"><a href="class.datetime.html" class="classname">DateTime</a></span> 对象作为第一个参数。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-datetime.setdate-parameters">
  <h3 class="title">参数</h3>
  <dl>
   <dt>
<code class="parameter">object</code></dt>

<dd>
<p class="para">仅过程化风格：由 <span class="function"><a href="function.date-create.html" class="function">date_create()</a></span> 返回的 <span class="classname"><a href="class.datetime.html" class="classname">DateTime</a></span> 类型的对象。此函数会修改这个对象。</p></dd>

   
    <dt>
<code class="parameter">year</code></dt>

    <dd>

     <p class="para">
      年份。
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">month</code></dt>

    <dd>

     <p class="para">
      月份。
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">day</code></dt>

    <dd>

     <p class="para">
      日。
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-datetime.setdate-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回方法链修改后的 <span class="classname"><a href="class.datetime.html" class="classname">DateTime</a></span> 对象。
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-datetime.setdate-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="datetimeimmutable.setdate.html" class="function" rel="rdfs-seeAlso">DateTimeImmutable::setDate()</a> - Sets the date</span></li>
  </ul>
 </div>


</div></div></div></body></html>